/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.evans.springcloud.consumer.dept.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 *
 * @author wangsunjie
 */
@RestController
public class DeptConsumerController {
    
    @Autowired
    private RestTemplate restTemplate;
    
    // private static final String REST_URL_PREFIX = "http://127.0.0.1:8001";
    private static final String REST_URL_PREFIX = "http://SPRINGCLOUD-PROVIDER-DEPT";
    
    @PostMapping("/consumer/dept/add")
    public boolean add() {
        return restTemplate.postForObject(REST_URL_PREFIX + "/dept/add", "DEPTENTITY", Boolean.class);
    }
    
    @GetMapping(value = "/consumer/dept/get/{id}")
    public String get(@PathVariable("id") Long id) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/get/" + id, String.class);
    }
    
    @GetMapping("/consumer/dept/list")
    public List<String> list() {
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/queryAll", List.class);
    }
    
    
    
}
